import router from "@/router";
import { useUserStore } from "@/store/user";
export function logout(before?: () => void, after?: () => void) {
  const store = useUserStore();
  // token过期
  // 让用户重新登录，和退出登录的逻辑 是一样
  before && before();
  // 1. 清token
  localStorage.removeItem("token");
  // 2. 清空路由
  store.routes.forEach((item) => router.removeRoute(item.name));
  // 3. 清pinia
  store.username = "";
  store.menus = [];
  // 4. 跳转到login
  router.push("/login");
  // 调用callback
  after && after();
}
